package com.mb.app.appused.greendao;

import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Property;
import de.greenrobot.daogenerator.Schema;
import de.greenrobot.daogenerator.ToMany;

public class Creat {
	public static void main(String[] args) throws Exception {
		String path = System.getProperty("user.dir");
		String pack = "com.mb.app.appused.greendao.database";
		
		Schema schema = new Schema(1000, pack);

		addValue(schema);
		
		String out = path + "\\src\\";
		System.out.println(out);

		try {
			new DaoGenerator().generateAll(schema, out);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.print(e);
		}
	}

	private static void addValue(Schema schema) {

		Entity value = schema.addEntity("Histroy");
		value.addIdProperty();
		value.addStringProperty("packageName").notNull();
		value.addStringProperty("time");
		value.addStringProperty("type");
	}

	static void addCustomerOrder(Schema schema) {
		Entity customer = schema.addEntity("Customer");
		customer.addIdProperty();
		customer.addStringProperty("name").notNull();

		Entity order = schema.addEntity("Order");
		order.setTableName("ORDERS"); // "ORDER" is a reserved keyword
		order.addIdProperty();
		Property orderDate = order.addDateProperty("date").getProperty();
		Property customerId = order.addLongProperty("customerId").notNull().getProperty();
		order.addToOne(customer, customerId);

		ToMany customerToOrders = customer.addToMany(order, customerId);
		customerToOrders.setName("orders");
		customerToOrders.orderAsc(orderDate);
	}

}
